<?php

// $Id$

/**
 *
 */
require_once(TANGRA_MAIN_DIR.'form/fields/text/form_field_text_view.class.php');
require_once($WSC->get_document_root_dir().'/js/modules/extlib_js_fckeditor/fckeditor.php');


/**
 * Form field for FCK Editor
 *
 */
class Form_Field_FCKeditor_View extends Form_Field_Text_View {
	private $width;
	private $height;
	private $fck_config_options;

	function __construct($tpl_name, Form_Field_Text $field, $width = 500, $height = 400, $fck_config_options = array()) {
		parent::__construct($tpl_name, $field);
		$this->width = $width;
		$this->height = $height;
		$this->fck_config_options = $fck_config_options;
	}


	public function get_tple_exports() {
		global $WSC;
		$exports = parent::get_tple_exports();


		ob_start();

		$oFCKeditor = new FCKeditor($this->get_tpl_name()) ;

		$oFCKeditor->Config["CustomConfigurationsPath"] = "/js/modules/extlib_js_fckeditor/fckconfig.js"  ;

		$oFCKeditor->BasePath = '/js/modules/extlib_js_fckeditor/';

		if ($this->is_field_in_error()) {
			$oFCKeditor->Value = $this->field->get_html_value();
		} else {
			$oFCKeditor->Value = $this->field->get_value();
		}

		if ($this->width) {
			$oFCKeditor->Width = $this->width;
		}

		if ($this->height) {
			$oFCKeditor->Height = $this->height;
		}

		foreach($this->fck_config_options as $key => $value) {
			$oFCKeditor->$key = $value;
		}

		$oFCKeditor->Create() ;

		$html = ob_get_contents();
		ob_end_clean();

		$exports->add_pair($this->get_tpl_name().'_fckeditor_html', $html);

		return $exports;
	}
}


